package com.itqf.vo;

import java.util.List;

/**
 * projectName: gpshop
 *
 * @author: 赵伟风
 * time: 2021/7/22 15:57
 * description:分页vo
 */
public class PageBean<T> {


    private List<T> list;
    private int page;
    private int pageSize;
    /**
     * 总条数
     */
    private Long total;
    /**
     * 总页数
     * totalPage = total / pageSize  向上舍于!
     */
    private int totalPage;

    /**
     * 根据类别查询的关键字!
     */
    private String cId = "";

    /**
     * 模糊查询的关键字
     */
    private String key = "";


    public PageBean() {
    }

    /**
     * 快速构建pageBean对象 注意:不需要传入总页数!
     * 总页数是get方法运算!
     * @param list
     * @param page
     * @param pageSize
     * @param total
     */
    public PageBean(List<T> list, int page, int pageSize, Long total) {
        this.list = list;
        this.page = page;
        this.pageSize = pageSize;
        this.total = total;
    }

    public String getcId() {
        return cId;
    }

    public void setcId(String cId) {
        this.cId = cId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public int getTotalPage() {

        //技术分享库
        //int和Integer的区别?

        //11.0/2 5.5 6
        return (int) Math.ceil(total*1.0/pageSize);
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
}
